import { PureComponent } from "react";
import { Incrementaction } from "../store/createActors";
class Home extends PureComponent
{
    constructor()
    {
        super();
    }

     componentDidMount()
    {
        this.props.store.subscribe(
            () => {
               const state = this.props.store.getState()
               this.setState(
                {
                 counter: state.counter
                }
             )    
            }
        )
    }
    
    add(num)
    {
        this.props.store.dispatch(Incrementaction(num));
    }

    render()
    {
        console.log(this.props)
        return (
            <div>
                <div>
                     <h2>Home</h2>
                    <div>counter:{this.props.store.getState().counter}</div>
                    <div>
                        <button onClick={() => this.add(1)}>+1</button>
                         <button onClick={()=>this.add(5)}>+5</button>
                         <button onClick={()=>this.add(10)}>+10</button>
                    </div>
               </div>
            </div>
        )
    }
}

export default Home;